package com.niit.activity.config;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

import org.apache.ibatis.session.SqlSessionFactory;
import com.niit.activity.typehandler.StringBlobTypeHandler;

@Configuration
@MapperScan("com.niit.activity.mapper")
@EnableTransactionManagement
public class MyBatisConfig {
    @Bean
    public WebMvcConfigurer webMvcConfigurer() {
        return new WebMvcConfigurer() {
            @Override
            public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
                converters.add(new MappingJackson2HttpMessageConverter());
            }
        };
    }

    @Bean
    public String registerTypeHandlers(SqlSessionFactory sqlSessionFactory) {
        sqlSessionFactory.getConfiguration().getTypeHandlerRegistry().register(new StringBlobTypeHandler());
        return "Initialized";
    }
}